package hezi.firebase;

import org.apache.log4j.Logger;

import com.firebase.client.ChildEventListener;
import com.firebase.client.Firebase;
import com.firebase.client.Query;

public class PostWaiter {
	public static Logger logger = Logger.getLogger("");
	public static Firebase sourceRef = new Firebase("https://luntankong.firebaseIO.com/runtime/post/source/");
	

	public static void publishPost(PostS postS,String qname) {
		sourceRef.child(qname+"/"+postS.getPostid()).setValue(postS);
	}


	public static void main(String[] args) {
		startListen();
	}


	public static void startListen() {
		logger.info("PostWaiter startListen");
		ChildEventListener eventListener = new NeedLoadChildEventListenerDF();
//		Query q = sourceRef.child("needload").startAt().limit(3000);
//		q.addChildEventListener(eventListener);
		
		sourceRef.child("needload").addChildEventListener(eventListener);
		
		
	}


	private static void test() {
		int sourceCount=0;
		for(int i = 0; i < 100; i++){
			try {
				Thread.currentThread().sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			sourceRef.child("p"+i).setValue("v"+i);
			logger.info("in:" + i);
		}
		
		ChildEventListener eventListener = new NeedLoadChildEventListener();
		sourceRef.addChildEventListener(eventListener);
	}


	

}
